import Vue from "vue"
import Vuex from "vuex"
Vue.use(Vuex)
import {addshopcars} from "../components/util/axios"
export default new Vuex.Store({
      state:{
       shoparr:[],
       num:1,
      },
      getters:{
        getshoparr(state){
          return state.shoparr
        },
        getnum(state){
            return state.num
        }
      },
      mutations:{
        REQ_SHOPARR(state,payload){
            state.shoparr = payload
            console.log(state.shoparr);
        }
      },
      actions:{
          //添加购物车的数据
          addShopcarActions({commit},data){
              console.log(data,"点击加入购物车获得的数据");
            //   return
            addshopcars(data).then(res=>{
                console.log(res,"返回的结果");
                commit("REQ_SHOPARR",res.list)
            })
        }
      }
 
})